/*     */ package nc.pubimpl.bd.feature.frelation;
/*     */ 
/*     */ import java.util.ArrayList;
/*     */ import java.util.HashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import nc.impl.pubapp.pattern.data.vo.VOQuery;
/*     */ import nc.pubitf.bd.feature.frelation.IPubFrelationService;
/*     */ import nc.util.mmf.framework.base.MMArrayUtil;
/*     */ import nc.util.mmf.framework.base.MMValueCheck;
/*     */ import nc.util.mmf.framework.db.MMSqlBuilder;
/*     */ import nc.vo.bd.feature.frelation.entity.FrelationBodyVO;
/*     */ import nc.vo.bd.feature.frelation.entity.FrelationHeadVO;
/*     */ import nc.vo.bd.feature.frelation.param.FrelationParam;
/*     */ import nc.vo.pub.BusinessException;
/*     */ import nc.vo.pub.lang.UFDateTime;
/*     */ import nc.vo.pubapp.AppContext;
/*     */ import nc.vo.pubapp.pattern.exception.ExceptionUtils;
/*     */ import nc.vo.pubapp.pattern.pub.MapList;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class PubFrelationServiceImpl
/*     */   implements IPubFrelationService
/*     */ {
/*     */   public PubFrelationServiceImpl() {}
/*     */   
/*     */   public MapList<String, FrelationParam> queryRelation(FrelationParam param)
/*     */     throws BusinessException
/*     */   {
/*     */     try
/*     */     {
/*  40 */       String datetime = AppContext.getInstance().getServerTime().toString();
/*  41 */       MapList<String, FrelationParam> returnMapList = new MapList();
/*     */       
/*  43 */       MMSqlBuilder sqlBuilder1 = new MMSqlBuilder();
/*  44 */       sqlBuilder1.append(" where ");
/*  45 */       sqlBuilder1.append("pk_group", param.getPk_group());
/*  46 */       sqlBuilder1.append(" and ");
/*  47 */       sqlBuilder1.append("cfeatureclsid", param.getCfeatureclsid());
/*  48 */       VOQuery<FrelationHeadVO> voquery = new VOQuery(FrelationHeadVO.class, new String[] { "cfrelationid", "cfeatureclsid" });
/*     */       
/*     */ 
/*  51 */       FrelationHeadVO[] headvos = (FrelationHeadVO[])voquery.queryWithWhereKeyWord(sqlBuilder1.toString(), null);
/*  52 */       if (MMArrayUtil.isEmpty(headvos)) {
/*  53 */         return returnMapList;
/*     */       }
/*     */       
/*  56 */       MMSqlBuilder sqlBuilder2 = new MMSqlBuilder();
/*  57 */       sqlBuilder2.append(" where ");
/*  58 */       sqlBuilder2.append("cfrelationid", new String[] { headvos[0].getCfrelationid() });
/*     */       
/*     */ 
/*  61 */       sqlBuilder2.append(" and ");
/*  62 */       sqlBuilder2.append("(");
/*  63 */       sqlBuilder2.append("(");
/*  64 */       sqlBuilder2.append("cfeatureid1 = '" + param.getCfeatureid() + "'");
/*  65 */       sqlBuilder2.append(" and ");
/*  66 */       if (param.getVfvalue() == null) {
/*  67 */         sqlBuilder2.append("vfvalue1 is null");
/*     */       }
/*     */       else {
/*  70 */         sqlBuilder2.append("vfvalue1 = '" + param.getVfvalue() + "'");
/*     */       }
/*  72 */       sqlBuilder2.append(")");
/*  73 */       sqlBuilder2.append(" or ");
/*  74 */       sqlBuilder2.append("(");
/*  75 */       sqlBuilder2.append("cfeatureid2 = '" + param.getCfeatureid() + "'");
/*  76 */       sqlBuilder2.append(" and ");
/*  77 */       if (param.getVfvalue() == null) {
/*  78 */         sqlBuilder2.append("vfvalue2 is null");
/*     */       }
/*     */       else {
/*  81 */         sqlBuilder2.append("vfvalue2 = '" + param.getVfvalue() + "'");
/*     */       }
/*  83 */       sqlBuilder2.append(")");
/*  84 */       sqlBuilder2.append(")");
/*  85 */       sqlBuilder2.and();
/*  86 */       sqlBuilder2.append("dbegindate <= '" + datetime + "' and " + "denddate" + " > '" + datetime + "'");
/*     */       
/*  88 */       VOQuery<FrelationBodyVO> voquery2 = new VOQuery(FrelationBodyVO.class);
/*  89 */       FrelationBodyVO[] bodyvos = (FrelationBodyVO[])voquery2.queryWithWhereKeyWord(sqlBuilder2.toString(), null);
/*  90 */       if (MMArrayUtil.isEmpty(bodyvos)) {
/*  91 */         return returnMapList;
/*     */       }
/*  93 */       for (FrelationBodyVO bodyvo : bodyvos) {
/*  94 */         if (MMValueCheck.isEmpty(bodyvo.getVfrealvalue1())) {
/*  95 */           bodyvo.setVfrealvalue1(bodyvo.getVfvaluename1());
/*     */         }
/*  97 */         if (MMValueCheck.isEmpty(bodyvo.getVfrealvalue2())) {
/*  98 */           bodyvo.setVfrealvalue2(bodyvo.getVfvaluename2());
/*     */         }
/*     */       }
/* 101 */       for (FrelationBodyVO bodyvo : bodyvos) {
/* 102 */         if ((bodyvo.getCfeatureid1() + bodyvo.getVfvalue1() + bodyvo.getVfrealvalue1() + bodyvo.getVfvaluename1()).equals(param.getCfeatureid() + param.getVfvalue() + param.getVfrealvalue() + param.getVfvaluename()))
/*     */         {
/*     */ 
/* 105 */           FrelationParam newParam = new FrelationParam();
/*     */           
/* 107 */           newParam.setPk_group(param.getPk_group());
/*     */           
/* 109 */           newParam.setCfeatureclsid(param.getCfeatureclsid());
/*     */           
/* 111 */           newParam.setCfeatureid(bodyvo.getCfeatureid2());
/*     */           
/* 113 */           newParam.setVfvalue(bodyvo.getVfvalue2());
/* 114 */           newParam.setVfrealvalue(bodyvo.getVfrealvalue2());
/* 115 */           newParam.setVfvaluename(bodyvo.getVfvaluename2());
/* 116 */           returnMapList.put(bodyvo.getVrelation().toString(), newParam);
/*     */         }
/* 118 */         else if ((bodyvo.getCfeatureid2() + bodyvo.getVfvalue2() + bodyvo.getVfrealvalue2() + bodyvo.getVfvaluename2()).equals(param.getCfeatureid() + param.getVfvalue() + param.getVfrealvalue() + param.getVfvaluename()))
/*     */         {
/*     */ 
/* 121 */           FrelationParam newParam = new FrelationParam();
/*     */           
/* 123 */           newParam.setPk_group(param.getPk_group());
/*     */           
/* 125 */           newParam.setCfeatureclsid(param.getCfeatureclsid());
/*     */           
/* 127 */           newParam.setCfeatureid(bodyvo.getCfeatureid1());
/*     */           
/* 129 */           newParam.setVfvalue(bodyvo.getVfvalue1());
/* 130 */           newParam.setVfrealvalue(bodyvo.getVfrealvalue1());
/* 131 */           newParam.setVfvaluename(bodyvo.getVfvaluename1());
/* 132 */           returnMapList.put(bodyvo.getVrelation().toString(), newParam);
/*     */         }
/*     */       }
/* 135 */       return returnMapList;
/*     */     }
/*     */     catch (Exception e) {
/* 138 */       ExceptionUtils.marsh(e);
/*     */     }
/* 140 */     return null;
/*     */   }
/*     */   
/*     */   public Map<String, String> queryRelation(FrelationParam[] params) throws BusinessException
/*     */   {
/* 145 */     String datetime = AppContext.getInstance().getServerTime().toString();
/* 146 */     Map<String, String> result = new HashMap();
/*     */     
/* 148 */     MMSqlBuilder sqlBuilder1 = new MMSqlBuilder();
/* 149 */     sqlBuilder1.append(" where ");
/* 150 */     sqlBuilder1.append("pk_group", params[0].getPk_group());
/* 151 */     sqlBuilder1.append(" and ");
/* 152 */     sqlBuilder1.append("cfeatureclsid", params[0].getCfeatureclsid());
/* 153 */     VOQuery<FrelationHeadVO> voquery = new VOQuery(FrelationHeadVO.class, new String[] { "cfrelationid", "cfeatureclsid" });
/*     */     
/*     */ 
/* 156 */     FrelationHeadVO[] headvos = (FrelationHeadVO[])voquery.queryWithWhereKeyWord(sqlBuilder1.toString(), null);
/* 157 */     if (MMArrayUtil.isEmpty(headvos)) {
/* 158 */       return result;
/*     */     }
/* 160 */     List<String> vFValueList = new ArrayList();
/* 161 */     List<String> cFeatureidList = new ArrayList();
/*     */     
/* 163 */     boolean isNullNeed = false;
/* 164 */     for (FrelationParam itParam : params) {
/* 165 */       cFeatureidList.add(itParam.getCfeatureid());
/* 166 */       if (itParam.getVfvalue() != null) {
/* 167 */         vFValueList.add(itParam.getVfvalue());
/*     */       } else {
/* 169 */         isNullNeed = true;
/*     */       }
/*     */     }
/*     */     
/*     */ 
/* 174 */     MMSqlBuilder sqlBuilder2 = new MMSqlBuilder();
/* 175 */     sqlBuilder2.append(" where ");
/* 176 */     sqlBuilder2.append("cfrelationid", new String[] { headvos[0].getCfrelationid() });
/*     */     
/*     */ 
/* 179 */     sqlBuilder2.append(" and ");
/* 180 */     sqlBuilder2.append("(");
/* 181 */     sqlBuilder2.append("(");
/* 182 */     sqlBuilder2.append("cfeatureid1", cFeatureidList);
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 191 */     sqlBuilder2.append(")");
/* 192 */     sqlBuilder2.append(" or ");
/* 193 */     sqlBuilder2.append("(");
/* 194 */     sqlBuilder2.append("cfeatureid2", cFeatureidList);
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 202 */     sqlBuilder2.append(")");
/* 203 */     sqlBuilder2.append(")");
/* 204 */     sqlBuilder2.and();
/* 205 */     sqlBuilder2.append("dbegindate <= '" + datetime + "' and " + "denddate" + " > '" + datetime + "'");
/*     */     
/* 207 */     VOQuery<FrelationBodyVO> voquery2 = new VOQuery(FrelationBodyVO.class);
/* 208 */     FrelationBodyVO[] bodyvos = (FrelationBodyVO[])voquery2.queryWithWhereKeyWord(sqlBuilder2.toString(), null);
/* 209 */     if (MMArrayUtil.isEmpty(bodyvos)) {
/* 210 */       return result;
/*     */     }
/* 212 */     String seperator1 = "|";
/* 213 */     String seperator2 = "&";
/* 214 */     String key = null;
/* 215 */     for (FrelationBodyVO itBody : bodyvos) {
/* 216 */       key = params[0].getCfeatureclsid() + "&" + itBody.getCfeatureid1() + "&" + itBody.getVfrealvalue1() + "&" + itBody.getVfvalue1() + "&" + itBody.getVfvaluename1();
/* 217 */       key = key + "|";
/* 218 */       key = key + params[0].getCfeatureclsid() + "&" + itBody.getCfeatureid2() + "&" + itBody.getVfrealvalue2() + "&" + itBody.getVfvalue2() + "&" + itBody.getVfvaluename2();
/* 219 */       result.put(key, itBody.getVrelation().toString());
/*     */     }
/* 221 */     return result;
/*     */   }
/*     */ }

